﻿namespace My.Hydrator.Tests.Helpers
{
    using System;
    using System.Collections.Generic;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using My.Hydrator.Helpers;

    [TestClass]
    public class TypeExtensionsTests
    {
        [TestMethod]
        public void IsNullableShouldPassForValidTypes()
        {
            Assert.AreEqual(true, typeof(int?).IsNullable());
            Assert.AreEqual(true, typeof(double?).IsNullable());
            Assert.AreEqual(true, typeof(DateTime?).IsNullable());
            Assert.AreEqual(true, typeof(long?).IsNullable());
            Assert.AreEqual(true, typeof(short?).IsNullable());
            Assert.AreEqual(true, typeof(float?).IsNullable());
        }

        [TestMethod]
        public void IsEnumerableShouldPassForValidTypes()
        {
            Assert.AreEqual(true, typeof(IEnumerable<>).IsEnumerable());
            Assert.AreEqual(true, typeof(IList<>).IsList());
            Assert.AreEqual(true, typeof(IList<>).IsList());
        }

        [TestMethod]
        public void IsListShouldPassForValidTypes()
        {
            Assert.AreEqual(true, typeof(IList<>).IsList());
            Assert.AreEqual(true, typeof(IList<>).IsList());
        }

        [TestMethod]
        public void IsDictionaryShouldPassForValidTypes()
        {
            Assert.AreEqual(true, typeof(IDictionary<,>).IsDictionary());
            Assert.AreEqual(true, typeof(Dictionary<,>).IsDictionary());
        }

        [TestMethod]
        public void HasParameterlessConstructorShouldPassForValidTypes()
        {
            Assert.AreEqual(true, typeof(Dictionary<,>).HasParameterlessConstructor());
            Assert.AreEqual(true, typeof(List<>).HasParameterlessConstructor());
        }

        [TestMethod]
        public void HasParameterlessConstructorShouldFailForInValidTypes()
        {
            Assert.AreEqual(false, typeof(string).HasParameterlessConstructor());
            Assert.AreEqual(false, typeof(int).HasParameterlessConstructor());
            Assert.AreEqual(false, typeof(DateTime).HasParameterlessConstructor());
        }
    }
}
